package com.lotus.lqmp.service.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lotus.idaas.sdk.common.BaseResult;
import com.lotus.lqmp.base.biz.bean.PageQuery;
import com.lotus.lqmp.service.biz.bean.EcuDetailExportModel;
import com.lotus.lqmp.service.common.utils.ExcelUtils;
import com.lotus.lqmp.service.controller.vo.req.EcuDetailQueryReq;
import com.lotus.lqmp.service.controller.vo.resp.EcuDetailQueryResp;
import com.lotus.lqmp.service.service.EcuInventoryDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.*;


/**
 * ECU清单详情表Controller
 *
 * @author Shiheng.Liu1
 * @date 2022-03-29
 */
@Slf4j
@RestController
@Api(tags = "ECU详情")
@RequestMapping("/api/ecuInventoryDetail")
public class EcuInventoryDetailController{
    @Autowired
    private EcuInventoryDetailService EcuInventoryDetailService;

    /**
     * 查询ECU详情记录
     * @param queryInfo：ECU详情查询限制条件
     * @return：响应ECU详情查询结果
     */
    @ApiOperation("ECU详情查询")
    @PostMapping("/findAll")
    public BaseResult<Page<EcuDetailQueryResp>> queryEcuDetail(@RequestBody PageQuery<EcuDetailQueryReq> queryInfo){
        //todo
        Page<EcuDetailQueryResp> page = new Page<>(queryInfo.getPageNum(), queryInfo.getPageSize());
        page.setRecords(Collections.singletonList(new EcuDetailQueryResp()));
        page.setTotal(1);
        return BaseResult.ok(page);
    }

    /**
     * 导出ECU详情记录
     * @param response：响应对象
     * @param ids：ECU详情导出限制条件
     */
    @ApiOperation("ECU详情导出")
    @RequestMapping(value = "/export", method = {RequestMethod.GET, RequestMethod.POST})
    public void exportEcuDetail(HttpServletResponse response, @RequestBody List<String> ids){
        //todo.根据regionIds查询关联信息
        List<EcuDetailExportModel> list = new ArrayList<>();
        //下载文件的默认名称
        try {
            // 导出操作
            ExcelUtils.exportExcel(list,null, "sheet1", EcuDetailExportModel.class, "ECU导出模板.xls", response);
            response.getOutputStream().close();
        } catch (Exception e) {
            log.info(e.getMessage());
        }
    }

}
